/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * frmQuanLySanPham.java
 *
 * Created on Aug 22, 2012, 3:08:26 PM
 */
package gui;

import dao.DanhMucDAO;
import dao.DonViTinhDAO;
import dao.SanPhamDAO;
import java.util.List;
import java.util.Vector;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import pojo.Danhmuc;
import pojo.Donvitinh;
import pojo.Sanpham;

/**
 *
 * @author dtth
 */
public class frmQuanLySanPham extends javax.swing.JFrame {

    private int _irow;
    private List<Donvitinh> _ldvt;
    private List<Danhmuc> _ldm;
    private List<Sanpham> _lsp;

    /** Creates new form frmQuanLySanPham */
    public frmQuanLySanPham() {
        initComponents();

        this._irow = 0;
        this._ldvt = null;
        this._ldm = null;
        this._lsp = SanPhamDAO.layDanhSachSanPham();

        //lay  du lieu vao combobox Don vi Tinh
        fillJcbxDonViTinh();
        //lay  du lieu vao combobox Danh muc
        fillJcbxDanhMuc();
        //day du lieu vao table
        fillJTable(this._lsp);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jtfTenSanPham = new javax.swing.JTextField();
        jtfDonGia = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jcbxDonViTinh = new javax.swing.JComboBox();
        jcbxDanhMuc = new javax.swing.JComboBox();
        jbtnTimKiem = new javax.swing.JButton();
        jbtnThem = new javax.swing.JButton();
        jtfMaSanPham = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jbtnSua = new javax.swing.JButton();
        jbtnXoa = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        jtbSanhPham = new javax.swing.JTable();
        jbtnDong = new javax.swing.JButton();
        jbtnLamMoi = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel1.setText("QUẢN LÝ SẢN PHẨM");

        jLabel3.setText("Tên Sản Phẩm");

        jLabel2.setText("Mã Sản Phẩm");

        jLabel5.setText("Đơn Vị Tính");

        jLabel6.setText("Danh Mục");

        jbtnTimKiem.setText("Tìm Kiếm");
        jbtnTimKiem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnTimKiemActionPerformed(evt);
            }
        });

        jbtnThem.setText("Thêm");
        jbtnThem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnThemActionPerformed(evt);
            }
        });

        jtfMaSanPham.setEditable(false);

        jLabel4.setText("Đơn Giá");

        jbtnSua.setText("Sửa");
        jbtnSua.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnSuaActionPerformed(evt);
            }
        });

        jbtnXoa.setText("Xóa");
        jbtnXoa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnXoaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(35, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4))
                        .addGap(28, 28, 28)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jtfDonGia)
                            .addComponent(jtfTenSanPham)
                            .addComponent(jtfMaSanPham, javax.swing.GroupLayout.PREFERRED_SIZE, 173, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jbtnTimKiem))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(34, 34, 34)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel6)
                                .addGap(25, 25, 25))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel5)
                                .addGap(18, 18, 18)))
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jcbxDonViTinh, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jcbxDanhMuc, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jbtnThem, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbtnSua, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbtnXoa, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(12, 12, 12)))
                .addGap(23, 23, 23))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jcbxDonViTinh, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jcbxDanhMuc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(jtfMaSanPham, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(jtfTenSanPham, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jtfDonGia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4))))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbtnTimKiem)
                    .addComponent(jbtnThem)
                    .addComponent(jbtnSua)
                    .addComponent(jbtnXoa))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jtbSanhPham.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jtbSanhPham.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jtbSanhPhamMouseClicked(evt);
            }
        });
        jtbSanhPham.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jtbSanhPhamKeyPressed(evt);
            }
        });
        jScrollPane2.setViewportView(jtbSanhPham);

        jbtnDong.setText("Đóng");
        jbtnDong.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnDongActionPerformed(evt);
            }
        });

        jbtnLamMoi.setText("Làm mới");
        jbtnLamMoi.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnLamMoiActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(251, 251, 251)
                .addComponent(jLabel1))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(398, 398, 398)
                        .addComponent(jbtnLamMoi, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jbtnDong, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 590, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addComponent(jLabel1)
                .addGap(11, 11, 11)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(11, 11, 11)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 185, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbtnDong)
                    .addComponent(jbtnLamMoi))
                .addGap(19, 19, 19))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jbtnTimKiemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnTimKiemActionPerformed
// TODO add your handling code here:
    int maDanhMuc = this._ldm.get(this.jcbxDanhMuc.getSelectedIndex()).getMadanhmuc();
    List<Sanpham> lsp = null;
    lsp = SanPhamDAO.timKiemSanPham(this.jtfTenSanPham.getText(), maDanhMuc);
    if (lsp.size() > 0) {
        fillJTable(lsp);
    } else {
        JOptionPane.showMessageDialog(this, "Không tìm thấy !", "Thông báo", JOptionPane.INFORMATION_MESSAGE);
    }
}//GEN-LAST:event_jbtnTimKiemActionPerformed

private void jbtnThemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnThemActionPerformed
// TODO add your handling code here:
    Sanpham sp = new Sanpham();
    sp.setTensanpham(this.jtfTenSanPham.getText());
    sp.setDongia(Double.valueOf(this.jtfDonGia.getText()));
    sp.setDanhmuc(this._ldm.get(this.jcbxDanhMuc.getSelectedIndex()));
    sp.setDonvitinh(this._ldvt.get(this.jcbxDonViTinh.getSelectedIndex()));

    boolean kq = SanPhamDAO.themSanPham(sp);
    if (kq) {
        JOptionPane.showMessageDialog(this, "Thêm thành công !", "Thông báo", JOptionPane.INFORMATION_MESSAGE);
    } else {
        JOptionPane.showMessageDialog(this, "Không thêm đươc !", "Thông báo", JOptionPane.WARNING_MESSAGE);
    }

    this._lsp = SanPhamDAO.layDanhSachSanPham();
    fillJTable(this._lsp);
    this.jtfMaSanPham.setText("");
    this.jtfTenSanPham.setText("");
    this.jtfDonGia.setText("");
}//GEN-LAST:event_jbtnThemActionPerformed

private void jbtnSuaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnSuaActionPerformed
// TODO add your handling code here:
    Sanpham sp = new Sanpham();
    sp.setMasanpham(Integer.valueOf(this.jtfMaSanPham.getText()));
    sp.setTensanpham(this.jtfTenSanPham.getText());
    sp.setDongia(Double.valueOf(this.jtfDonGia.getText()));
    sp.setDanhmuc(this._ldm.get(this.jcbxDanhMuc.getSelectedIndex()));
    sp.setDonvitinh(this._ldvt.get(this.jcbxDonViTinh.getSelectedIndex()));

    boolean kq = SanPhamDAO.capnhatThongTinSanPham(sp);
    if (kq) {
        JOptionPane.showMessageDialog(this, "Cập nhật thành công !", "Thông báo", JOptionPane.INFORMATION_MESSAGE);
    } else {
        JOptionPane.showMessageDialog(this, "Cập nhật không được !", "Thông báo", JOptionPane.WARNING_MESSAGE);
    }

    this._lsp = SanPhamDAO.layDanhSachSanPham();
    fillJTable(this._lsp);
    this.jtfMaSanPham.setText(this.jtbSanhPham.getModel().getValueAt(_irow, 0).toString());
    this.jtfTenSanPham.setText(this.jtbSanhPham.getModel().getValueAt(_irow, 1).toString());
    this.jtfDonGia.setText(this.jtbSanhPham.getModel().getValueAt(_irow, 2).toString());
}//GEN-LAST:event_jbtnSuaActionPerformed

private void jbtnXoaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnXoaActionPerformed
// TODO add your handling code here:
    Sanpham sp = new Sanpham();
    sp.setMasanpham(Integer.valueOf(this.jtfMaSanPham.getText()));

    boolean kq = SanPhamDAO.xoaSanPham(sp);
    if (kq) {
        JOptionPane.showMessageDialog(this, "Xóa thành công !", "Thông báo", JOptionPane.INFORMATION_MESSAGE);
    } else {
        JOptionPane.showMessageDialog(this, "Xóa không được !", "Thông báo", JOptionPane.WARNING_MESSAGE);
    }

    this._lsp = SanPhamDAO.layDanhSachSanPham();
    fillJTable(this._lsp);
    this.jtfMaSanPham.setText("");
    this.jtfTenSanPham.setText("");
    this.jtfDonGia.setText("");
}//GEN-LAST:event_jbtnXoaActionPerformed

private void jbtnDongActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnDongActionPerformed
// TODO add your handling code here:
//    System.exit(1);
    this.setVisible(false);
}//GEN-LAST:event_jbtnDongActionPerformed

private void jtbSanhPhamKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtbSanhPhamKeyPressed
// TODO add your handling code here:
    int key = evt.getKeyCode();
    //JOptionPane.showMessageDialog(this, key, "Thông báo", JOptionPane.INFORMATION_MESSAGE);
    _irow = this.jtbSanhPham.getSelectedRow();
    if (key == 40) {//nhan nut xuong
        _irow++;
    }
    if (key == 38) {//nhan nutlen
        _irow--;
    }

    //lây du lieu tai dong dang chon trong table dua vao cac textfield
    this.jtfMaSanPham.setText(this.jtbSanhPham.getModel().getValueAt(_irow, 0).toString());
    this.jtfTenSanPham.setText(this.jtbSanhPham.getModel().getValueAt(_irow, 1).toString());
    this.jtfDonGia.setText(this.jtbSanhPham.getModel().getValueAt(_irow, 3).toString());

    //lay danh muc cua hang vua dc chon trong table vao combpbox Danhmuc
    this.jcbxDanhMuc.setEditable(true);
    this.jcbxDanhMuc.setSelectedItem(this._lsp.get(_irow).getDanhmuc().getTendanhmuc());
    this.jcbxDanhMuc.setEditable(false);

    //lay danh muc cua hang vua dc chon trong table vao combpbox Don vi tinh
    this.jcbxDonViTinh.setEditable(true);
    this.jcbxDonViTinh.setSelectedItem(this._lsp.get(_irow).getDonvitinh().getTendonvitinh());
    this.jcbxDonViTinh.setEditable(false);
}//GEN-LAST:event_jtbSanhPhamKeyPressed

private void jtbSanhPhamMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jtbSanhPhamMouseClicked
// TODO add your handling code here:
    _irow = this.jtbSanhPham.getSelectedRow();

    //lây du lieu tai dong dang chon trong table dua vao cac textfield
    this.jtfMaSanPham.setText(this.jtbSanhPham.getModel().getValueAt(_irow, 0).toString());
    this.jtfTenSanPham.setText(this.jtbSanhPham.getModel().getValueAt(_irow, 1).toString());
    this.jtfDonGia.setText(this.jtbSanhPham.getModel().getValueAt(_irow, 3).toString());

    //lay danh muc cua hang vua dc chon trong table vao combpbox Danhmuc
    this.jcbxDanhMuc.setEditable(true);
    this.jcbxDanhMuc.setSelectedItem(this._lsp.get(_irow).getDanhmuc().getTendanhmuc());
    this.jcbxDanhMuc.setEditable(false);

    //lay danh muc cua hang vua dc chon trong table vao combpbox Don vi tinh
    this.jcbxDonViTinh.setEditable(true);
    this.jcbxDonViTinh.setSelectedItem(this._lsp.get(_irow).getDonvitinh().getTendonvitinh());
    this.jcbxDonViTinh.setEditable(false);
}//GEN-LAST:event_jtbSanhPhamMouseClicked

private void jbtnLamMoiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnLamMoiActionPerformed
// TODO add your handling code here:
    fillJTable(this._lsp);
    this.jtfMaSanPham.setText("");
    this.jtfTenSanPham.setText("");
    this.jtfDonGia.setText("");
}//GEN-LAST:event_jbtnLamMoiActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(frmQuanLySanPham.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(frmQuanLySanPham.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(frmQuanLySanPham.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(frmQuanLySanPham.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new frmQuanLySanPham().setVisible(true);
            }
        });
    }

    private void fillJTable(List<Sanpham> lsp) {
        DefaultTableModel tableModel = new DefaultTableModel();
        tableModel.addColumn("Mã Sản Phẩm");
        tableModel.addColumn("Tên Sản Phẩm");
        tableModel.addColumn("Danh Mục");
        tableModel.addColumn("Đơn Giá");
        tableModel.addColumn("Đơn Vị Tính");
        this.jtbSanhPham.setModel(tableModel);
        if (lsp.size() > 0) {
            for (int i = 0; i < lsp.size(); i++) {
                Vector vt = new Vector();
                vt.add(lsp.get(i).getMasanpham());
                vt.add(lsp.get(i).getTensanpham());
                vt.add(lsp.get(i).getDanhmuc().getTendanhmuc());
                vt.add(lsp.get(i).getDongia());
                vt.add(lsp.get(i).getDonvitinh().getTendonvitinh());

                tableModel.addRow(vt);
            }
        }
    }

    //ham lay thong tin don vi tin tu CSDL vao combobox DonViTinh
    private void fillJcbxDonViTinh() {
        DefaultComboBoxModel cbxModel = new DefaultComboBoxModel();
        this.jcbxDonViTinh.setModel(cbxModel);

        this._ldvt = DonViTinhDAO.layDanhSachDonViTinh();
        for (int i = 0; i < _ldvt.size(); i++) {
            cbxModel.addElement(_ldvt.get(i).getTendonvitinh());
        }
    }

    //ham lay thong tin don vi tin tu CSDL vao combobox DanhMuc
    private void fillJcbxDanhMuc() {
        DefaultComboBoxModel cbxModel = new DefaultComboBoxModel();
        this.jcbxDanhMuc.setModel(cbxModel);

        this._ldm = DanhMucDAO.layDanhSachDanhMuc();
        for (int i = 0; i < this._ldm.size(); i++) {
            cbxModel.addElement(this._ldm.get(i).getTendanhmuc());
        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JButton jbtnDong;
    private javax.swing.JButton jbtnLamMoi;
    private javax.swing.JButton jbtnSua;
    private javax.swing.JButton jbtnThem;
    private javax.swing.JButton jbtnTimKiem;
    private javax.swing.JButton jbtnXoa;
    private javax.swing.JComboBox jcbxDanhMuc;
    private javax.swing.JComboBox jcbxDonViTinh;
    private javax.swing.JTable jtbSanhPham;
    private javax.swing.JTextField jtfDonGia;
    private javax.swing.JTextField jtfMaSanPham;
    private javax.swing.JTextField jtfTenSanPham;
    // End of variables declaration//GEN-END:variables
}
